*** Get all botox claims from carrier files
foreach YEAR of numlist 2002/2016{

	* Grab certain variables from carrier files
	disp `YEAR'
	cd /disk/aging/medicare/data/harm/20pct/car
	use hcpcs_cd expnsdt2 lprvpmt line_icd_dgns_cd if inlist(hcpcs_cd, "J0585", "64612", "64613", "64614"  "64640", "64650", "67345") using `YEAR'/carl`YEAR'.dta 
	
	* Tag treated vs untreated botox 
	rename line_icd_dgns_cd diagnosis
	replace hcpcs_cd = "botox_treated" if diagnosis == "72885"| diagnosis == "3518"| diagnosis == "33383"| diagnosis == "7235"| diagnosis == "78830"| diagnosis == "78831"| diagnosis == "78832"| diagnosis == "78833"| diagnosis == "78834"| diagnosis == "59982"
	replace hcpcs_cd = "botox_untreated" if hcpcs_cd!= "botox_treated"

	* Panelize 
	gen month = mofd(expnsdt2)
	collapse (sum) lprvpmt, by(month hcpcs_cd)

	* Save
	save /disk/agedisk3/medicare.work/poterba-DUA52260/jetson-dua52260/botox/synth/100pct/raw/carrier/carrier_botox_panel_`YEAR'.dta, replace 
}

*** append to 1 file

cd /disk/agedisk3/medicare.work/poterba-DUA52260/jetson-dua52260/botox/synth/100pct/raw/carrier/
use carrier_botox_panel_2002.dta 
foreach YEAR of numlist 2003/2016{
	append using carrier_botox_panel_`YEAR'.dta
}
rename month dt 
save carrier_botox_panel.dta, replace 

***********************************************************************************************
*** Get all other hcpcs codes in carrer
foreach YEAR of numlist 2002/2016{

	* Grab certain variables from carrier files
	disp `YEAR'
	cd /disk/aging/medicare/data/harm/20pct/car
	use hcpcs_cd expnsdt2 lprvpmt if !inlist(hcpcs_cd, "J0585", "64612", "64613", "64614"  "64640", "64650", "67345") using `YEAR'/carl`YEAR'.dta 

	* Panelize 
	gen month = mofd(expnsdt2)
	collapse (sum) lprvpmt, by(month hcpcs_cd)

	* Save
	save /disk/agedisk3/medicare.work/poterba-DUA52260/jetson-dua52260/botox/synth/100pct/raw/carrier/carrier_hcpcs_panel_`YEAR'.dta 
}


*** append to 1 file

cd /disk/agedisk3/medicare.work/poterba-DUA52260/jetson-dua52260/botox/synth/100pct/raw/carrier/
use carrier_hcpcs_panel_2002.dta 
foreach YEAR of numlist 2003/2016{
	append using carrier_hcpcs_panel_`YEAR'.dta
}
rename month dt 
save carrier_hcpcs_panel.dta, replace 



